//package com.zoweunion.mechanic.netty;
//
//import javax.annotation.Resource;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//import com.zoweunion.mechanic.config.NettyConfig;
//import io.netty.bootstrap.ServerBootstrap;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.ChannelOption;
//import io.netty.channel.EventLoopGroup;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.nio.NioServerSocketChannel;
//
//@Component
//@Order(2)
//public class DiscardServer implements ApplicationRunner {
//	@Resource
//	private NettyConfig nettyConfig;
//
//	@Resource
//	private ChildChannelHandler childChannelHandler;
//
//	public void run(int port) throws Exception {
//		EventLoopGroup bossGroup = new NioEventLoopGroup();
//		EventLoopGroup workerGroup = new NioEventLoopGroup();
//		System.out.println("准备运行端口：" + nettyConfig.getPort());
//		try {
//			ServerBootstrap bootstrap = new ServerBootstrap();
//			bootstrap.group(bossGroup, workerGroup)
//			.channel(NioServerSocketChannel.class)
//			//.channel(OioServerSocketChannel.class)
//			.option(ChannelOption.SO_BACKLOG, 128)
//			.childHandler(childChannelHandler);
//			//绑定端口，同步等待成功
//			ChannelFuture f = bootstrap.bind(nettyConfig.getIp(),nettyConfig.getPort()).sync();
//			//等待服务监听端口关闭
//			System.out.println("--------------------------------测试此处是否阻塞1------------------------------------------------------------");
//			f.channel().closeFuture().sync();//经测试此方法会一直阻塞serverchannel关闭
//			System.out.println("--------------------------------测试此处是否阻塞2------------------------------------------------------------");
//		} finally {
//			//退出，释放线程资源
//			workerGroup.shutdownGracefully();
//			bossGroup.shutdownGracefully();
//		}
//	}
//	@Override
//	public void run(ApplicationArguments args) throws Exception {
//
//		run(nettyConfig.getPort());
//	}
//}
